<template>
	<view class="wrap">
		<view style="padding: 30rpx;">
			<u-link href="https://remixicon.com/">https://remixicon.com/</u-link>
		</view>
		<view class="u-icon-item" v-for="(item, index) in iconList" :key="index" @tap="selectIcon(item,index)">
			<view class="u-icon-id">{{index+1}}</view>
			<i-icon size="80rpx" :name="item.name" :color="item.color"></i-icon>
			<view class="u-icon-name" :style="{'color':(item.color)}">{{item.name}}</view>
		</view>

	</view>
</template>

<script>
	export default {
		data() {
			return {
				iconList: [{
						name: 'arrow-left-up-line'
					},
					{
						name: 'arrow-up-line'
					},
					{
						name: 'arrow-right-up-line'
					},
					{
						name: 'arrow-right-line'
					},
					{
						name: 'arrow-right-down-line'
					},
					{
						name: 'arrow-down-line'
					},
					{
						name: 'arrow-left-down-line'
					},
					{
						name: 'arrow-left-line'
					},
					{
						name: 'ancient-gate-line'
					},
					{
						name: 'medal-line'
					},
					{
						name: 'code-box-line'
					},
					{
						name: 'palette-fill'
					},
					{
						name: 'git-branch-line'
					},
					{
						name: 'fingerprint-line'
					},
					{
						name: 'wifi-line'
					},
					{
						name: 'translate'
					},
					{
						name: 'vip-line'
					},
					{
						name: 'cake-2-line'
					},
					{
						name: 'heart-pulse-line'
					},
					{
						name: 'alipay-fill'
					},
					{
						name: 'twitter-fill'
					},
					{
						name: 'motorbike-line'
					},
					{
						name: 'camera-lens-line'
					},
					{
						name: 'star-line'
					},
					{
						name: 'alarm-warning-fill'
					},
					{
						name: 'loader-2-line'
					},
					{
						name: 'emotion-line'
					},
					{
						name: 'billiards-fill'
					},
					{
						name: 'leaf-fill'
					},
					{
						name: 'recycle-fill'
					},
					{
						name: 'signpost-line'
					},
					{
						name: 'discount-percent-line'
					},	
				]
			};
		},
		onShow() {
			this.getData()
		},
		methods: {
			getData() {
				// this.iconList.sort(function(s1, s2) {
				// 	// console.log(s1.name);
				// 	let x1 = s1.name.toUpperCase();
				// 	// console.log(x1);
				// 	let x2 = s2.name.toUpperCase();
				// 	if (x1 < x2) {
				// 		return -1;
				// 	}
				// 	if (x1 > x2) {
				// 		return 1;
				// 	}
				// 	return 0;
				// });
				// this.iconList.map((item, index) => {
				// 	item.color = this.getRandomColor();
				// 	return item
				// })
			},
			selectIcon(item, index) {
				// console.log(item);
				// // #ifdef H5
				// return this.$u.toast('H5暂不支持复制');
				// // #endif
				uni.setClipboardData({
					data: item.name,
					success: () => {
						item.color = this.getRandomColor();
						this.iconList.splice()
					}
				});
				uni.hideToast()
				this.$u.toast(item.name);
			},

			getRandomColor() {
				// 随机生成颜色
				const letters = '0123456789ABCDEF';
				let color = '#';
				for (let i = 0; i < 6; i++) {
					color += letters[Math.floor(Math.random() * 16)];
				}
				return color;
			},
		}
	}
</script>

<style scoped lang="scss">
	.wrap {
		padding: 24rpx;
	}

	.inner-wrap {
		display: flex;
		flex-wrap: wrap;
	}

	.u-icon-item {
		display: flex;
		align-items: center;
		padding: 10rpx 0;
		background-color: white;
		margin-bottom: 10rpx;
		border-radius: 10rpx;
	}

	.u-icon-id {
		width: 60rpx;
		margin-right: 10rpx;
		text-align: right;
	}

	.u-icon-name {
		color: $u-tips-color;
		word-wrap: break-word;
		word-break: break-all;
		font-size: 26rpx;
		padding: 0 14rpx;
		// 给定高度是为了图标名超出一行时，进行换行能有更好的效果
	}
</style>